﻿
#include "subject.h"

#include "concreteobserver.h"

Subject::Subject()
{

}

void Subject::attach(Observer *observer)
{
    m_observerList.append(observer);
}

void Subject::detach(Observer *observer)
{
    ObserverList::iterator it = m_observerList.begin();
    for (; it != m_observerList.end(); it++) {
        if (*it == observer) {
            m_observerList.erase(it);
            return;
        }
    }
}

void Subject::notify()
{
    ObserverList::iterator it = m_observerList.begin();
    for (; it != m_observerList.end(); it++) {
        (*it)->update(this);
    }
}
